#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#define MAX_FILE_HANDLES 100000
int main() {
	    int fds[MAX_FILE_HANDLES];
	        for (int i = 0; i < MAX_FILE_HANDLES; i++) {
			        fds[i] = open("test.txt", O_RDONLY);
				        if (fds[i] == -1) {
						            perror("open");
							                printf("Maximum file handles: %d\n", i);
									            sleep(120);
										                exit(1);
												        }
					    }
		    printf("Maximum file handles: %d\n", MAX_FILE_HANDLES);
		        sleep(120);
			    for (int i = 0; i < MAX_FILE_HANDLES; i++) {
				            if (close(fds[i]) == -1) {
						                perror("close");
								            exit(1);
									            }
					        }
			        return 0;
}
